package atguigu.neixing;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

public class IntrospectorDemo {

	public static void main(String[] args) {
		
		UserInfo userInfo = new UserInfo();
		userInfo.setAge(10);
		userInfo.setEmailAddress("mailfendou@163.com");
		userInfo.setUserId(111);
		userInfo.setUserName("张三");
		
		BeanInfo beanInfo;
		try {
			beanInfo = Introspector.getBeanInfo(UserInfo.class);
			PropertyDescriptor[] proDescrtptors = beanInfo.getPropertyDescriptors();
	        if(proDescrtptors!=null && proDescrtptors.length>0){
	            for(PropertyDescriptor propDesc:proDescrtptors){
//	            	System.out.println(propDesc.getName());
	            	String displayName = propDesc.getDisplayName();
	            	System.out.println(displayName);
//	            	Method readMethod = propDesc.getReadMethod();
//	            	Object invoke = readMethod.invoke(userInfo);
//	            	System.out.println(propDesc.getName()+":"+invoke);
	            }
	        }
		} catch (IntrospectionException e) {
			e.printStackTrace();
		} /*
			 * catch (IllegalAccessException e) { // TODO Auto-generated catch block
			 * e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO
			 * Auto-generated catch block e.printStackTrace(); } catch
			 * (InvocationTargetException e) { // TODO Auto-generated catch block
			 * e.printStackTrace(); }
			 */
        
	}
}
